package com.selfdriving.activity;

import com.selfdriving.R;
import com.selfdriving.bean.JsonResolveUtils;
import com.selfdriving.view.MarqueeTextView;
import com.selfdriving.view.ViewFlipperView;
import net.tsz.afinal.annotation.view.ViewInject;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ActivityNoticeActivity extends BaseActivity
{
	/** VF容器 **/
	@ViewInject(id = R.id.vf_layout)
	LinearLayout viewFlipperRL;
	/** VF底部点点 **/
	@ViewInject(id = R.id.radio_layout)
	private LinearLayout Lradio;

	@ViewInject(id = R.id.tvScrollView)
	MarqueeTextView tvScrollView;

	@ViewInject(id = R.id.ivImg1, click = "ivImg")
	ImageView ivImg;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_notice);
		getHomeVFData();
	}

	@Override
	protected void onResume()
	{
		tvScrollView.requestFocus();
		super.onResume();
	}

	private void getHomeVFData()
	{
		putAsyncTask(new AsyncTask<Void, Void, Boolean>()
		{

			@Override
			protected void onPreExecute()
			{
				super.onPreExecute();
			}

			@Override
			protected Boolean doInBackground(Void... params)
			{
				return JsonResolveUtils.resolveHomeVF(mApplication);
			}

			@Override
			protected void onPostExecute(Boolean result)
			{
				super.onPostExecute(result);
				if (result)
				{

					if (viewFlipperRL.getChildCount() > 0)
					{
						viewFlipperRL.removeAllViews();
					}
					ViewFlipperView flipperView = new ViewFlipperView(
							ActivityNoticeActivity.this, Lradio, 0,
							mApplication.homeList);
					viewFlipperRL
							.addView(flipperView.viewFlipper, layoutParams);
				} else
				{
					showToast("加载失败。");
				}
			}
		});
	}

	public void ivImg(View v)
	{
		if (!isLogin())
		{
			Intent intent = new Intent(this, RegisterActivity.class);
			startActivity(intent);
		} else
		{
			Intent intent = new Intent(this, FeatureDetailsActivity.class);
			startActivity(intent);
		}
	}
}
